// pages/cityList/index.js
var app = getApp();
var ajax = require('../../utils/ajax.js');
var common = require('../../utils/common.js');
var area = require('../../utils/area.js');
var PageBase = require('../../common/PageBase.js');


Page({

  /**
   * 页面的初始数据
   */
  data: {
    winHei: 0,
    citys: [],
    currentTab: null,
    cityList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var _self = this;
    this.setData({
      city: wx.getStorageSync('locCity')
    })
    wx.getSystemInfo({
      success: function(res) {
        _self.setData({
          winHei: 750 / res.windowWidth * res.windowHeight
        });
      },
      fail: function(res) {

      },
      complete: function(res) {

      }
    })

    area.init(this);

    this.data.areaData.forEach((item, index) => {
      var cityItem = {};
      cityItem.name = item.name;
      cityItem.code = item.code;
      this.data.cityList.push(cityItem);
    })
    this.setData({
      cityList: this.data.cityList
    })
  },
  _switchCity(evt) {
    var city = evt.currentTarget.dataset.curCity;
    wx.setStorageSync('city', city);
    wx.navigateBack();
  },
  _tabSwitch(evt) {
    const code = evt.currentTarget.dataset.code;
    const curTab = evt.currentTarget.dataset.curTab;
    const areaData = this.data.areaData;
    areaData.some((item, index) => {
      if (code == areaData[index].code) {
        this._citys = areaData[index].sub;
      }
    })
    this.setData({
      citys: this._citys,
      currentTab: curTab
    })
  }
})